package cn.gson.school.controller.jiuye;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.gson.school.dao.jiuye.ResumeEntityDao;
import cn.gson.school.dao.jiuye.ResumeEvaluateEntityDao;
import cn.gson.school.entity.jiuye.InterviewExperienceEntity;
import cn.gson.school.entity.jiuye.ResumeEntity;
import cn.gson.school.entity.jiuye.ResumeEvaluateEntity;
import cn.gson.school.entity.jiuye.ResumeProjectEntity;
import cn.gson.school.mappers.jiuye.ResumeEntityMapper;
import cn.gson.school.mappers.jiuye.ResumeEvaluateEntityMapper;
import cn.gson.school.mappers.jiuye.ResumeProjectEntityMapper;

/**
 * 简历
 * 
 * @author 华少
 *
 */
@Controller
@RequestMapping("/jianli")
public class ResumeEntityController {
	@Autowired
	private ResumeEntityMapper resumeEntityMapper;
	@Autowired
	private ResumeEntityDao resumeEntityDao;
	@Autowired
	private ResumeProjectEntityMapper resumeProjectEntityMapper;
	@Autowired
	private ResumeEvaluateEntityMapper resumeEvaluateEntityMapper;
	@Autowired
	private ResumeEvaluateEntityDao resumeEvaluateEntityDao;
	@RequestMapping("jianli")
	@ResponseBody
	public Map<String,Object> indxt (ResumeEntity resumeEntity,
			@RequestParam(name = "page", defaultValue = "1") int pageNum,
			@RequestParam(name = "rows", defaultValue = "20") int pageSize){
		PageHelper.startPage(pageNum, pageSize);
		List<ResumeEntity> listDate=resumeEntityMapper.list(resumeEntity);
		PageInfo<ResumeEntity> info=new PageInfo<>(listDate);
		Map<String,Object> obj=new HashMap<String,Object>();
		obj.put("total", info.getTotal());
		obj.put("rows", info.getList());
		return obj;
	}
	@GetMapping({"jy-jl-tianjiajianli","jy-jl-tianjiajianli/{id}"})
	public String form(@PathVariable(name = "id", required = false) Long id, Model model) {
		
		ResumeEntity u=resumeEntityDao.chaxunduixian(id);
		if(null!=u) {
			List<ResumeProjectEntity> project=resumeProjectEntityMapper.chaxunxiangmu(u.getResumeId());
			List<ResumeEvaluateEntity> evaluate=resumeEvaluateEntityMapper.chaxunpingjia(u.getResumeId());
			model.addAttribute("resume",u);
			model.addAttribute("project",project);
			model.addAttribute("evaluate",evaluate);
		}
		return "jiuye/jy-jl-tianjiajianli";
	}
	
	@PostMapping("save")
	@ResponseBody
	@Transactional
	public Map<String,Object> save(@Valid ResumeEvaluateEntity resumeEvaluateEntity, BindingResult br){
		Map<String, Object> obj = new HashMap<String, Object>();
		obj.put("success", false);
		if(!resumeEvaluateEntity.equals(null)){
			resumeEvaluateEntity.setResumeEvaluateContent(resumeEvaluateEntity.getResumeEvaluateContent());
			resumeEvaluateEntity.setResumeEvaluateDate(new Date());
			resumeEvaluateEntity.setResumeId(resumeEvaluateEntity.getResumeId());
			resumeEvaluateEntity.setUserinfoId(resumeEvaluateEntity.getUserinfoId());
			resumeEvaluateEntityDao.save(resumeEvaluateEntity);
		}
		obj.put("success", true);
		return obj;
	}	
	
}
